package cn.yeziji.netty;

import cn.yeziji.netty.server.NettyWebsocketServer;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

import javax.annotation.Resource;

/**
 * netty 启动主程序
 *
 * @author gzkemays
 * @since 2022/11/07 4:22 PM
 */
@SpringBootApplication
@ComponentScan(
    value = {
      "cn.yeziji.netty.config",
      "cn.yeziji.netty.server",
      "cn.yeziji.netty.adapter",
      "cn.yeziji.forum.utils",
      "cn.yeziji.forum.config"
    })
public class NettyApplication implements CommandLineRunner {
  @Resource NettyWebsocketServer nettyServer;

  @Resource(name = "cpuTaskExecutor")
  ThreadPoolTaskExecutor cpuTaskExecutor;

  public static void main(String[] args) {
    SpringApplication.run(NettyApplication.class, args);
  }

  @Override
  public void run(String... args) {
    cpuTaskExecutor.submit(() -> {
      nettyServer.start(12345);
    });
  }
}
